package com.module.app.base.loadsir;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.module.base.base.loadsir.ErrorViewUtils;
import com.module.base.network.exception.ServerException;
import com.kingja.loadsir.callback.Callback;
import com.module.app.R;


public class ErrorCallback extends Callback {

    @Override
    protected int onCreateView() {
        return R.layout.app_layout_loadsir_error;
    }

    @Override
    protected void onViewCreate(Context context, View view) {
        //设置错误信息
        ServerException error = ErrorViewUtils.getError();
        if (view != null && getTitleView(view) != null) {
            TextView textView = getTitleView(view);
            if (textView != null) {
                if (error != null && !TextUtils.isEmpty(error.getMsg())) {
                    textView.setText(error.getMsg());
                } else {
                    textView.setText(R.string.empty_error);
                }
            }
        }
        super.onViewCreate(context, view);
    }


    public ViewGroup getLayout(View view) {
        ViewGroup layout = view.findViewById(R.id.layout);
        return layout;
    }

    public ViewGroup getLogoView(View view) {
        ViewGroup layout_logo = view.findViewById(R.id.layout_logo);
        return layout_logo;
    }

    public ImageView getLogoImageView(View view) {
        ImageView layout_logo = view.findViewById(R.id.loadsir_iv_logo);
        return layout_logo;
    }

    public TextView getTitleView(View view) {
        return view.findViewById(R.id.loadsir_tv_title);
    }

    public TextView getSubTitleView(View view) {
        return view.findViewById(R.id.tv_subtitle);
    }

    public TextView getBtn(View view) {
        return view.findViewById(R.id.tv_btn);
    }
}
